# coding:utf-8

import requests
import re

from sina_数据 import showChart
import numpy as np
from sina_数据.单独的货币分析.单K线的获取 import get_data_from_sina
from sina_数据.各国货币波动情况分析.例子_USD import get_all_Symbol

from sina_数据.欧美.欧美1H数据分析 import showChart


def analysis_near_UP_and_DOWN(Symbol='usd'):
    for i in get_all_Symbol('usd'):
        data = get_data_from_sina(get_all_Symbol())
    up = 0


def arrangement_data(symbol='usdcad'):
    # 将直接带日期的数据进行整理获取不带日期的字典形式的数据
    # data = get_data_from_sina(symbol)

    data = []
    for i in get_data_from_sina(symbol):
        data.append([i['o'], i['l'], i['h'], i['c']])
    # print(a)
    return data


def 在MA偏离周期内的最高值():
    # 与均线相交的周期分析
    data = get_data_from_sina()
    MA_period = 60

    for i in range(len(data)):
        now = data[i]
        MA = sum([float(n['c']) for n in data[i - MA_period:i]]) / MA_period
        if now['h'] > MA and now['l'] < MA:
            # print('当前相交')
            # print('当前相交的时间为', now['d'])
            上一次相交 = i

    print()
    showChart.showHistogram_x()


if __name__ == '__main__':
    # 开盘    最低    最高    收盘
    a = arrangement_data()
    print(a)

    在MA偏离周期内的最高值()

    # a = get_data_from_sina()
    # print(a)
    # a = [[1, 21, 3, 3, 3], [1, 21, 3, 3, 3], [1, 21, 3, 3, 3], [1, 21, 3, 3, 3], [1, 21, 3, 3, 3]]
    # # print([[o, p, q, r] for i in a for o, p, q, r in zip(i)])
    # print([[o, p, q, r] for o, p, q, r in zip(range(5), range(5), range(5), range(5), )])
    # data = get_data_from_sina()
    # print([[d, o, l, h, c]] for d, o, l, h, c in zip())
    # a = []
    # for i in data:
    #     a.append([i['o'], i['l'], i['h'], i['c']])
    # print(a)

    # s = [[h, o, d, l] for i in data for h, o, d, l in zip(i)]
    # print(s)
